@svizzle/utils/[any-number]-[array-number]

Methods

(static) arrayMaxWith(fn) → {function}

Source:
Since:
  • 0.1.0
See:

Return a function expecting an array of objects and returning the max of results of applying the provided fuction on all of the array items

Example
> maxWithAbsSin = arrayMaxWith(_.pipe([Math.sin, Math.abs]))
> maxWithAbsSin([-Math.PI/2, -Math.PI/4])
1
> maxWithAbsSin([Math.PI/4, Math.PI/6])
0.7071067811865475
Parameters:
Name Type Description
fn function
Returns:
  • Array -> Number
Type
function

(static) arrayMinWith(fn) → {function}

Source:
Since:
  • 0.1.0
See:

Return a function expecting an array of objects and returning the min of results of applying the provided fuction on all of the array items

Example
> minWithAbsSin = arrayMinWith(_.pipe([Math.sin, Math.abs]))
> minWithAbsSin([-Math.PI/2, -Math.PI/4])
0.7071067811865475
> minWithAbsSin([Math.PI/4, Math.PI/6])
0.49999999999999994
Parameters:
Name Type Description
fn function
Returns:
  • Array -> Number
Type
function

(static) arraySumWith(accessor) → {function}

Source:
Since:
  • 0.16.0
See:

Return a function expecting an array and summing the numbers obtained from applying the provided accessor to the array items. Note that it skips items where the accessor does not return a number.

Example
> sumValues = arraySumWith(_.getKey('a'))
> sumValues([{a: 1}, {a: 2}, {a: 3}])
6
> sumValues([{a: 1}, {a: 2}, {a: 'hey'}])
3
> sumValues([{a: 1}, {a: 2}, {notA: 3}])
3
> sumValues([{a: 'hey'}, {notA: 'b'}, {notA: 3}])
0
> sumValues([])
0
Parameters:
Name Type Description
accessor function

Any -> Number

Returns:
  • Array -> Number
Type
function

(static) makeAverageWith(accessor) → {function}

Source:
Since:
  • 0.11.0

Return the average of values of a {key, value}[] array

Example
> makeAverageOfA = makeAverageWith(_.getKey('a'));
> makeAverageOfA([
	{a: 1, b: 2},
	{a: 10, b: 7},
	{a: 7, b: 9},
])
6
> makeAverageOfA([])
0
Parameters:
Name Type Description
accessor function

Any -> Number

Returns:
  • Array -> Number
Type
function